package com.hyx.api.service.impl.pc_admin;

import java.util.*;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.hyx.api.mapper.MsgDialogueOrderMapper;
import com.hyx.api.domain.MsgDialogueOrder;
import com.hyx.api.domain.bo.MsgDialogueOrderBo;
import com.hyx.api.domain.vo.MsgDialogueOrderVo;
import com.hyx.api.service.pc_admin.IMsgDialogueOrderService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;

/**
 * 订单消息对话Service业务层处理
 *
 * @author HK
 * @date 2023-11-05
 */
@RequiredArgsConstructor
@Service
public class MsgDialogueOrderServiceImpl implements IMsgDialogueOrderService
{
    private final MsgDialogueOrderMapper msgDialogueOrderMapper;

    /**
     * 查询订单消息对话列表
     *
     * @param bo 订单消息对话
     * @return 订单消息对话
     */
    @Override
    public List<MsgDialogueOrderVo> selectMsgDialogueOrderList(MsgDialogueOrderBo bo, Long userId)
    {
        List<MsgDialogueOrderVo> list = msgDialogueOrderMapper.queryMsgVoList(bo);
        Set<Long> ids = new HashSet<>();
        list.forEach(it -> {
            if(Objects.equals(it.getReceiveUser(), userId)) {
                if(it.getIsRead() == 0)
                    ids.add(it.getId());
            }
        });
        if(!ids.isEmpty())
            msgDialogueOrderMapper.setReadByIds(ids);
        return list;
    }
}

